﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using InkFx.WinControl.Core;

namespace InkFx.WinControl
{
    /// <summary>
    /// 表示组成应用程序的用户界面的窗口或对话框。
    /// </summary>
    public class NoneForm : System.Windows.Forms.Form
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        public NoneForm()
        {
            base.SetStyle(ControlStyles.Selectable, false);

            //base.DoubleBuffered = true; //这种需要快速弹出的窗体, 设置 双缓冲 只会减慢启动速度
            base.ShowInTaskbar = false;
            base.FormBorderStyle = FormBorderStyle.None;
            base.TransparencyKey = Win32API.Transparent;
            base.StartPosition = FormStartPosition.Manual;
        }

        /// <summary>
        /// 内部字段
        /// </summary>
        protected Rectangle m_InitBounds = Rectangle.Empty;

        /// <summary>
        /// 以非激活模式 显示窗体
        /// </summary>
        /// <param name="owner">任何实现 System.Windows.Forms.IWin32Window 并表示将拥有此窗体的顶级窗口的对象。</param>
        public virtual new void Show(IWin32Window owner)
        {
            this.Show(owner, Rectangle.Empty);
        }
        /// <summary>
        /// 以非激活模式 显示窗体
        /// </summary>
        /// <param name="owner">Type: IWin32Window</param>
        /// <param name="bounds">Type: Rectangle</param>
        public virtual new void Show(IWin32Window owner, Rectangle bounds)
        {
            base.Owner = owner as System.Windows.Forms.Form;
            base.Bounds = new Rectangle(-100, -100, 2, 2);
            Win32API.ShowWindow(this.Handle, 4);
            base.OnLoad(EventArgs.Empty);
            base.OnShown(EventArgs.Empty);
        }
        
        /// <summary>
        /// 引发 System.Windows.Forms.Form.Shown 事件。
        /// </summary>
        /// <param name="e">一个包含事件数据的 System.EventArgs。</param>
        protected override void OnShown(EventArgs e)
        {
            base.OnShown(e);
            base.DoubleBuffered = true;  //在正式显示后 再开启双缓冲
            if (m_InitBounds.Width >= 1 && m_InitBounds.Height >= 1) base.Bounds = m_InitBounds;
        }
    }
}
